package cn.kim.edu.info.manager.service;

import cn.kim.edu.info.manager.dao.StudentDao;
import cn.kim.edu.info.manager.domain.Student;

public class StudentService {
    //创建StudentDao实体
    StudentDao studentDao = new StudentDao();

    //具体实现添加的方法
    public boolean addStudent(Student stu) {
        return studentDao.addStudent(stu);
    }

    //判断ID号是否存在
    public boolean isExists(String id) {
        Student[] stuns = studentDao.findAllStudent();
        //假设id在数组中不存在
        boolean exists = false;
        for (int i = 0; i < stuns.length; i++) {
            Student student = stuns[i];
            if (student != null && student.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    //实现查看学生的方法
    public Student[] findAdllStudent() {
        //调用方法
        Student[] allStudent = studentDao.findAllStudent();
        //判断数组中是否有职员信息
        boolean flag = false;
        for (int i = 0; i < allStudent.length; i++) {
            Student sts = allStudent[i];
            if (sts != null) {
                flag = true;
                break;
            }
        }

        if (flag) {
            return allStudent;
        } else {
            return null;
        }
    }

    //方法层
    public void deleteStudentById(String delId) {
        studentDao.deleteStudentById(delId);
    }

    //修改学生信息
    public void updateStudent(String updateId, Student newStu) {
        studentDao.updateStudent(updateId,newStu);
    }
}
